package cc.mrbird.monitoring.controller;

import cc.mrbird.assets.domain.AssetMana;
import cc.mrbird.assets.domain.AssetType;
import cc.mrbird.common.annotation.Log;
import cc.mrbird.common.controller.BaseController;
import cc.mrbird.common.domain.ResponseBo;
import cc.mrbird.monitoring.domain.Monitoring;
import cc.mrbird.monitoring.service.MonitoringService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@Api(description = "资产监控管理接口")
@Controller
public class MonitoringController extends BaseController {

    private Logger log = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private MonitoringService monitoringService;
    @Log("获取资产监控信息")
    @RequestMapping(value = "monitoring",method = RequestMethod.POST)
    /* @RequiresPermissions("monitoring:list")*/
    public String index() {
        return "asset/monitoring/monitoring";
    }
    @Log("获取不同资产类型信息")
    @ApiOperation(value = "获取不同资产类型信息" ,  notes="获取不同资产类型信息")
    @RequestMapping(value = "monitoring/findAllTypeAndId",method = RequestMethod.GET)
    @ResponseBody
    public ResponseBo  findAllTypeAndId(){
        try {
            List<AssetType> allTypeAndId = monitoringService.findAllTypeAndId();
            Map<String,List<AssetMana>> AllAssetManaByType = new HashMap<>();
            for (AssetType assetType : allTypeAndId) {
                String group_concat = assetType.getGroup_concat();
                List<AssetMana> assetManas = monitoringService.fingAllByIds(group_concat);
                AllAssetManaByType.put(assetType.getAsset_type_name(),assetManas);
            }
            return  ResponseBo.ok(AllAssetManaByType);
        } catch (Exception e) {
            return ResponseBo.error("获取不同类型数据失败,请联系管理员");
        }
    }
    @Log("获取不同资产类型设备信息")
    @ApiOperation(value = "获取不同资产类型设备信息" ,  notes="获取不同资产类型设备信息")
    @RequestMapping(value = "monitoring/findAllType",method = RequestMethod.GET)
    @ResponseBody
    public ResponseBo findAllType(){
        try {
            Monitoring monitoring = new Monitoring();
            List<AssetType> totalType = monitoringService.findAllTypeAndId();
            Map<String,List<Integer>> total_type = new HashMap<>();
            for (AssetType assetType : totalType) {
                List<Integer> numerByType = monitoringService.findNumerByType(assetType.getAsset_type_name());
                total_type.put(assetType.getAsset_type_name(),numerByType);
            }
            monitoring.setTotal_type(total_type);

            return  ResponseBo.ok(monitoring);
        } catch (Exception e) {
            return ResponseBo.error("获取所有单位设备运行信息失败,请联系管理员");
        }
    }
    @Log("获取设备详细信息")
    @ApiOperation(value = "获取设备详细信息" ,  notes="获取设备详细信息")
    @RequestMapping(value = "monitoring/findAllAssetByTypeAndStatus",method = RequestMethod.GET)
    @ResponseBody
    public ResponseBo findAllAssetByTypeAndStatus(String asset_type, Integer equipment_satus){
        try {
            if(asset_type==null||asset_type==""){

                return ResponseBo.error("参数类型有误,请重新输入");
            }
            if(equipment_satus==null){
                return ResponseBo.error("参数类型有误,请重新输入");
            }
            List<AssetMana> assetManaList =  monitoringService.findAllAssetByTypeAndStatus(asset_type,equipment_satus);
            return ResponseBo.ok(assetManaList);
        } catch (Exception e) {
            return ResponseBo.error("根据类型以及状态获取设备详细信息失败,请联系管理员");
        }
    }
}
